//
//  IDish.m
//  XRmenu
//
//  Created by yangxh on 11-3-24.
//  Copyright 2011 E0571. All rights reserved.
//

#import "IDish.h"


@implementation IDish

@synthesize dishId;
@synthesize Id;
@synthesize dishLanguaegExs;
@synthesize spellCode;

//=========================================================== 
// - (id)init
//
//=========================================================== 
- (id)init
{
    return [self initWithDishId:nil Id:0 dishLanguaegExs:nil];
}


//=========================================================== 
// - (id)initWith:
//
//=========================================================== 
- (id)initWithDishId:(NSString*)aDishId Id:(NSInteger)anId dishLanguaegExs:(NSArray*)aDishLanguaegExs 
{
    self = [super init];
    if (self) {
        self.dishId = aDishId;
        self.Id = anId;
        self.dishLanguaegExs = aDishLanguaegExs;
    }
    return self;
}


//=========================================================== 
// + (id)objectWith:
//
//=========================================================== 
+ (id)objectWithDishId:(NSString*)aDishId Id:(NSInteger)anId dishLanguaegExs:(NSArray*)aDishLanguaegExs  
{
    id result = [[[self class] alloc] initWithDishId:aDishId Id:anId dishLanguaegExs:aDishLanguaegExs];
	
    return [result autorelease];
}

//=========================================================== 
// - (NSArray *)keyPaths
//
//=========================================================== 
- (NSArray *)keyPaths
{
    NSArray *result = [NSArray arrayWithObjects:
					   @"dishId",
					   @"Id",
					   @"dishLanguaegExs",
					   @"spellCode",
					   nil];
	
    return result;
}


//=========================================================== 
// - (NSString *)descriptionForKeyPaths
//
//=========================================================== 
- (NSString *)descriptionForKeyPaths 
{
    NSMutableString *desc = [NSMutableString string];
    NSEnumerator *e = [[self keyPaths] objectEnumerator];
    NSString *thisKey;
    [desc appendString:@"\n\n"];
	
    while ((thisKey = [e nextObject])) {
        [desc appendFormat: @"%@: %@\n", thisKey, [self valueForKey:thisKey]];
    }
	
    return [NSString stringWithString:desc];
}

- (NSString *)description
{
	return [self descriptionForKeyPaths];
}

//=========================================================== 
// dealloc
//=========================================================== 
- (void)dealloc
{
    [dishId release];
    dishId = nil;
    [dishLanguaegExs release];
    dishLanguaegExs = nil;
	[spellCode release];
	spellCode = nil;
	
    [super dealloc];
}

+ (IDish *)iDishByParse:(NSDictionary *)info
{	
	NSArray *dishExs = dictObject(info,@"Dishexs");
	NSMutableArray *newDishExs = [NSMutableArray arrayWithCapacity:[dishExs count]];
	for (NSDictionary *item in dishExs) {
		IDishLanguageEx *dishEx = [IDishLanguageEx iDishLanguageExByParse:item];
		[newDishExs addObject:dishEx];
	}
	
	IDish *dish = [IDish objectWithDishId:dictObject(info,@"DishId")
									   Id:dictInt(info,@"ID")
						  dishLanguaegExs:newDishExs];
	dish.spellCode = dictObject(info,@"SpellCode");
	
	return dish;
}

@end
